package cn.iocoder.yudao.module.dt.controller.admin.activityadmin;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.dt.controller.admin.activityadmin.vo.*;
import cn.iocoder.yudao.module.dt.dal.dataobject.activityadmin.ActivityAdminDO;
import cn.iocoder.yudao.module.dt.convert.activityadmin.ActivityAdminConvert;
import cn.iocoder.yudao.module.dt.service.activityadmin.ActivityAdminService;

@Api(tags = "管理后台 - 活动管理员表，用作核销等权限")
@RestController
@RequestMapping("/dt/activity-admin")
@Validated
public class ActivityAdminController {

    @Resource
    private ActivityAdminService activityAdminService;

    @PostMapping("/create")
    @ApiOperation("创建活动管理员表，用作核销等权限")
    @PreAuthorize("@ss.hasPermission('dt:activity-admin:create')")
    public CommonResult<Integer> createActivityAdmin(@Valid @RequestBody ActivityAdminCreateReqVO createReqVO) {
        return success(activityAdminService.createActivityAdmin(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新活动管理员表，用作核销等权限")
    @PreAuthorize("@ss.hasPermission('dt:activity-admin:update')")
    public CommonResult<Boolean> updateActivityAdmin(@Valid @RequestBody ActivityAdminUpdateReqVO updateReqVO) {
        activityAdminService.updateActivityAdmin(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除活动管理员表，用作核销等权限")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('dt:activity-admin:delete')")
    public CommonResult<Boolean> deleteActivityAdmin(@RequestParam("id") Integer id) {
        activityAdminService.deleteActivityAdmin(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得活动管理员表，用作核销等权限")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('dt:activity-admin:query')")
    public CommonResult<ActivityAdminRespVO> getActivityAdmin(@RequestParam("id") Integer id) {
        ActivityAdminDO activityAdmin = activityAdminService.getActivityAdmin(id);
        return success(ActivityAdminConvert.INSTANCE.convert(activityAdmin));
    }

    @GetMapping("/list")
    @ApiOperation("获得活动管理员表，用作核销等权限列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('dt:activity-admin:query')")
    public CommonResult<List<ActivityAdminRespVO>> getActivityAdminList(@RequestParam("ids") Collection<Integer> ids) {
        List<ActivityAdminDO> list = activityAdminService.getActivityAdminList(ids);
        return success(ActivityAdminConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得活动管理员表，用作核销等权限分页")
    @PreAuthorize("@ss.hasPermission('dt:activity-admin:query')")
    public CommonResult<PageResult<ActivityAdminRespVO>> getActivityAdminPage(@Valid ActivityAdminPageReqVO pageVO) {
        PageResult<ActivityAdminDO> pageResult = activityAdminService.getActivityAdminPage(pageVO);
        return success(ActivityAdminConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出活动管理员表，用作核销等权限 Excel")
    @PreAuthorize("@ss.hasPermission('dt:activity-admin:export')")
    @OperateLog(type = EXPORT)
    public void exportActivityAdminExcel(@Valid ActivityAdminExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<ActivityAdminDO> list = activityAdminService.getActivityAdminList(exportReqVO);
        // 导出 Excel
        List<ActivityAdminExcelVO> datas = ActivityAdminConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "活动管理员表，用作核销等权限.xls", "数据", ActivityAdminExcelVO.class, datas);
    }

}
